﻿@{
    ViewBag.Title = "科室信息维护";
}
<style>
    div.k-edit-form-container {
        width: auto;
        -moz-min-width: 400px;
        -ms-min-width: 400px;
        -o-min-width: 400px;
        -webkit-min-width: 400px;
        min-width: 400px;
        max-width: 1800px;
    }

    div.k-window {
        width: 95%;
    }

    .k-edit-form-container .editor-label, .k-edit-label {
        width: 10%;
    }

    .k-edit-field, .k-edit-form-container .editor-field {
        width: 85%;
    }
    #grid > .k-grid-header > div > table,
#grid > .k-grid-content > table
{
   width: 100% !important;
}
</style>
<div id="grid" ></div>
    <script id="popup-editor" type="text/x-kendo-template">
        <div class="k-edit-label"><label for="DoctorName">科室名称</label></div>
        <div class="k-edit-field"><input data-bind="value:DepartName" required data-required-msg="请输入科室名称" class="k-textbox" name="DepartName" maxlength="50" /></div>
        <div class="k-edit-label"><label for="Loc">科室位置</label></div>
        <div class="k-edit-field"><input data-bind="value:Loc" required data-required-msg="请输入科室位置" class="k-textbox" name="Loc" maxlength="50" /></div>
        <div class="k-edit-label"><label for="Desc">描述</label></div>
        <div class="k-edit-field"><textarea data-bind="value:Desc" required data-required-msg="请输入描述" cols="120" rows="10" id="Desc" name="Desc"></textarea></div>
        <div class="k-edit-label"><label for="SortNo">排序</label></div>
        <div class="k-edit-field"><input data-bind="value:SortNo" type="number" value="17" min="0" max="1000" step="1" class="k-textbox" name="SortNo" id="SortNo" maxlength="4" /></div>
        <div class="k-edit-label"><label for="IsShow">是否显示</label></div>
        <div class="k-edit-field"><input type="checkbox" style='opacity: initial;position: unset;left:  unset;z-index: unset;width: auto;height: auto;' data-bind="checked:IsShow" value="1" name="IsShow" /></div>
    </script>
    <script>
        jQuery(function () {
            $(".sidebar-menu li").removeClass("active");
            $("#depart").addClass("active");

            var dataModel;
            var grid = jQuery("#grid").kendoGrid({
                "edit": function (e) {
                    //   e.container.find("#SortNo").kendoNumericTextBox({
                    //       format:"n0"
                    //});

                    if (!e.model.isNew()) {
                        // Disable the editor of the "id" column when editing data items
                        var nameField = e.container.find("input[name='DepartName']");
                        var name = nameField.val();
                        e.container.data("kendoWindow").title("编辑 " + name);
                    } else {
                        e.container.data("kendoWindow").title("新增");
                    }
                    dataModel = e.model;
                },
                "columns": [
                     {
                         "command": [{
                             "name": "edit",
                             "buttonType": "ImageAndText",
                             "text": {
                                 "cancel": "取消",
                                 "update": "更新",
                                 "edit": "编辑"
                             }
                         },
                         {
                             "name": "destroy",
                             "buttonType": "ImageAndText",
                             "text": "删除"
                         }],
                         width: "180px"
                     },
                     {
                         "title": "科室编号",
                         "headerAttributes": {
                             "data-field": "DepartNo",
                             "data-title": "科室编号"
                         },
                         "field": "DepartNo",
                         "filterable": {
                             "cell": {
                                 "showOperators": false,
                                 "operator": "contains"
                             }
                         },
                         width: "120px",
                         "encoded": true
                     },
                {
                    "title": "科室名称",
                    "headerAttributes": {
                        "data-field": "DepartName",
                        "data-title": "科室名称"
                    },
                    "field": "DepartName",
                    "filterable": {
                        "cell": {
                            "showOperators": false,
                            "operator": "contains"
                        }
                    },
                    width: "120px",
                    "encoded": true
                },
                {
                    "title": "描述",
                    "headerAttributes": {
                        "data-field": "Desc",
                        "data-title": "描述"
                    },
                    width: "120px",
                    "hidden": true,
                    "field": "Desc",
                    "filterable": {
                        "cell": {
                            "showOperators": false,
                            "operator": "contains"
                        }
                    },
                    "encoded": true
                },
                {
                    "title": "科室排序",
                    "headerAttributes": {
                        "data-field": "SortNo",
                        "data-title": "科室排序号"
                    },
                    "field": "SortNo",
                    "filterable": {
                        "cell": {
                            "showOperators": false,
                            "operator": "eq"
                        }
                    },
                    width: "80px",
                    "encoded": true
                },
                {
                    "title": "是否显示",
                    "headerAttributes": {
                        "data-field": "IsShow",
                        "data-title": "是否显示"
                    },
                    "field": "IsShow",
                    "filterable": false,
                    "template": '<strong>#: IsShow == 1?"是":"否" # </strong>',
                    width: "80px",
                    "encoded": true

                },
                {
                    "title": "创建时间",
                    "headerAttributes": {
                        "data-field": "CreateTime",
                        "data-title": "创建时间"
                    },
                    "field": "CreateTime",
                    "format": "{0:yyyy/MM/dd}",
                    "filterable": {
                        "cell": {
                            "showOperators": false,
                            "operator": "gte"
                        }
                    },
                    width: "120px",
                    "encoded": true
                },
                {
                    "title": "更新时间",
                    "headerAttributes": {
                        "data-field": "ModifiedTime",
                        "data-title": "更新时间"
                    },
                    "field": "ModifiedTime",
                    "format": "{0:yyyy/MM/dd}",
                    "filterable": {
                        "cell": {
                            "showOperators": false,
                            "operator": "gte"
                        }
                    },
                    width: "120px",
                    "encoded": true
                }],
                //"toolbar": [{ "name": "create", "text": "新增", "buttonType": "ImageAndText" }],
                "editable": { "mode": "popup", "template": kendo.template($("#popup-editor").html()), "window": { resizable: true }, "confirmation": true, "confirmDelete": "确定要删除吗？" },
                "pageable": {
                    "buttonCount": 10,
                    "messages": {
                        "display": "显示条目 {0} - {1} 共 {2}",
                        "empty": "没有可显示的记录。",
                        "page": "页",
                        "of": "共 {0}",
                        "first": "首页",
                        "previous": "前页",
                        "next": "后页",
                        "last": "末页",
                        "refresh": "刷新",
                        "morePages": "更多页"
                    }
                },
                "sortable": true,
                "filterable": {
                    "mode": "row"
                },
                scrollable: true,
                "navigatable": true,
                "messages": {
                    "noRecords": "没有可用的记录。"
                },
                "dataSource": {
                    "type": (function () {
                        if (kendo.data.transports['aspnetmvc-ajax']) {
                            return 'aspnetmvc-ajax';
                        } else {
                            throw new Error('The kendo.aspnetmvc.min.js script is not included.');
                        }
                    })(),
                    "transport": {
                        "read": {
                            "url": "@Url.Action("Departs_Read", "Grid")"
                        },
                        //"create": {
                        //    "url": + "/Grid/Depart_Create"
                        //},
                        "update": {
                            "url": "@Url.Action("Depart_Update", "Grid")"
                        },
                        "destroy": {
                            "url": "@Url.Action("Depart_Destroy", "Grid")"
                        },
                        "idField": "Id",
                        "prefix": ""
                    },
                    "pageSize": 20,
                    "page": 1,
                    "total": 0,
                    "serverPaging": true,
                    "serverSorting": true,
                    "serverFiltering": true,
                    "serverGrouping": true,
                    "serverAggregates": true,
                    "filter": [],
                    "schema": {
                        "data": "Data",
                        "total": "Total",
                        "errors": "Errors",
                        "model": {
                            "id": "Id",
                            "fields": {
                                "Id": {
                                    "type": "number"
                                },
                                "DepartNo": {
                                    "type": "string"
                                },
                                "Desc": {
                                    "type": "string"
                                },
                                "DepartName": {
                                    "type": "string"
                                },
                                "SortNo": {
                                    "type": "number",
                                    "defaultValue": null
                                },
                                "IsShow": {
                                    "type": "number",
                                    "defaultValue": null
                                },
                                "CreateTime": {
                                    "type": "date"
                                },
                                "ModifiedTime": {
                                    "type": "date",
                                    "defaultValue": null
                                }
                            }
                        }
                    }
                }
            });
        });

    </script>
